﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Apple.FrameCapture
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.IO;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;

#nullable disable
namespace UnityEngine.Apple
{
  /// <summary>
  ///   <para>Interface to control XCode Frame Capture.</para>
  /// </summary>
  [NativeHeader("Runtime/Export/Apple/FrameCaptureMetalScriptBindings.h")]
  [NativeConditional("PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_OSX")]
  public class FrameCapture
  {
    private FrameCapture()
    {
    }

    [FreeFunction("FrameCaptureMetalScripting::IsDestinationSupported")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool IsDestinationSupportedImpl(FrameCaptureDestination dest);

    [FreeFunction("FrameCaptureMetalScripting::BeginCapture")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void BeginCaptureImpl(FrameCaptureDestination dest, string path);

    [FreeFunction("FrameCaptureMetalScripting::EndCapture")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void EndCaptureImpl();

    [FreeFunction("FrameCaptureMetalScripting::CaptureNextFrame")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void CaptureNextFrameImpl(FrameCaptureDestination dest, string path);

    /// <summary>
    ///   <para>Is Capture destination supported.</para>
    /// </summary>
    /// <param name="dest"></param>
    public static bool IsDestinationSupported(FrameCaptureDestination dest)
    {
      return dest == FrameCaptureDestination.DevTools || dest == FrameCaptureDestination.GPUTraceDocument ? FrameCapture.IsDestinationSupportedImpl(dest) : throw new ArgumentException(nameof (dest), "Argument dest has bad value (not one of FrameCaptureDestination enum values)");
    }

    /// <summary>
    ///   <para>Begin Capture in XCode frame debugger.</para>
    /// </summary>
    public static void BeginCaptureToXcode()
    {
      if (!FrameCapture.IsDestinationSupported(FrameCaptureDestination.DevTools))
        throw new InvalidOperationException("Frame Capture with DevTools is not supported.");
      FrameCapture.BeginCaptureImpl(FrameCaptureDestination.DevTools, (string) null);
    }

    /// <summary>
    ///   <para>Begin Capture to the specified file.</para>
    /// </summary>
    /// <param name="path"></param>
    public static void BeginCaptureToFile(string path)
    {
      if (!FrameCapture.IsDestinationSupported(FrameCaptureDestination.GPUTraceDocument))
        throw new InvalidOperationException("Frame Capture to file is not supported.");
      if (string.IsNullOrEmpty(path))
        throw new ArgumentException(nameof (path), "Path must be supplied when capture destination is GPUTraceDocument.");
      if (Path.GetExtension(path) != ".gputrace")
        throw new ArgumentException(nameof (path), "Destination file should have .gputrace extension.");
      FrameCapture.BeginCaptureImpl(FrameCaptureDestination.GPUTraceDocument, new Uri(path).AbsoluteUri);
    }

    /// <summary>
    ///   <para>End Capture.</para>
    /// </summary>
    public static void EndCapture() => FrameCapture.EndCaptureImpl();

    /// <summary>
    ///   <para>Begin capture to Xcode at the beginning of the next frame, and end it at the end of the next frame.</para>
    /// </summary>
    public static void CaptureNextFrameToXcode()
    {
      if (!FrameCapture.IsDestinationSupported(FrameCaptureDestination.DevTools))
        throw new InvalidOperationException("Frame Capture with DevTools is not supported.");
      FrameCapture.CaptureNextFrameImpl(FrameCaptureDestination.DevTools, (string) null);
    }

    /// <summary>
    ///   <para>Begin capture to the specified file at the beginning of the next frame, and end it at the end of the next frame.</para>
    /// </summary>
    /// <param name="path"></param>
    public static void CaptureNextFrameToFile(string path)
    {
      if (!FrameCapture.IsDestinationSupported(FrameCaptureDestination.GPUTraceDocument))
        throw new InvalidOperationException("Frame Capture to file is not supported.");
      if (string.IsNullOrEmpty(path))
        throw new ArgumentException(nameof (path), "Path must be supplied when capture destination is GPUTraceDocument.");
      if (Path.GetExtension(path) != ".gputrace")
        throw new ArgumentException(nameof (path), "Destination file should have .gputrace extension.");
      FrameCapture.CaptureNextFrameImpl(FrameCaptureDestination.GPUTraceDocument, new Uri(path).AbsoluteUri);
    }
  }
}
